<template>
  <div class="g-modal-content flex-middle flex-center">
    <div
      :class="[
        'g-modal-content_mask animate__animated',
        { animate__fadeIn: visible },
        { animate__fadeOut: !visible },
      ]"
    ></div>
    <div
      @animationEnd="animationEnd"
      :class="[
        'g-modal-content_wrap animate__animated',
        { animate__fadeInDown: visible },
        { animate__fadeOutUp: !visible },
      ]"
    >
      <div class="g-modal-content_box">
        <div class="g-modal-content_title" v-if="title">{{ title }}</div>
        <div class="g-modal-content_body" v-if="content">{{ content }}</div>
        <div class="g-modal-content_buttons border-top flex">
          <div class="g-button flex1" @click="handleCancel">取消</div>
          <div class="g-button flex1" @click="handleConfirm">确定</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({
  props: {
    title: {
      type: String,
      default: "提示",
    },
    content: {
      type: String,
    },
    confirm: Function,
    cancel: Function,
  },
  data() {
    return {
      visible: false,
    };
  },
  created() {
    this.visible = true;
  },
  methods: {
    handleConfirm() {
      if (this.confirm) {
        this.confirm();
      } else {
        this.visible = false;
      }
    },
    handleCancel() {
      if (this.cancel) {
        this.cancel();
      } else {
        this.visible = false;
      }
    },
    close() {
      this.visible = false;
    },
    animationEnd() {
      if (!this.visible) {
        const childEl = document.getElementById("modal_content");
        if (childEl) {
          document.body.removeChild(childEl);
        }
      }
    },
  },
});
</script>
<style lang="scss" scoped>
.g-modal-content_mask,
.g-modal-content {
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}
.g-modal-content {
  background: none;
}
.g-modal-content_wrap {
  z-index: 100;
}
.g-modal-content_box {
  background: #fff;
  width: 480px;
  font-size: 40px;
  text-align: center;
  border-radius: 12px;
}
.g-modal-content_title {
  font-size: 32px;
  padding: 30px 0 30px;
}
.g-modal-content_body {
  font-size: 26px;
  padding: 0px 30px 30px;
  color: #333;
}
.g-modal-content_buttons {
  .g-button {
    border: none;
    padding: 20px 0;
    font-size: 30px;
    border-right: 1px solid #d7d7d7;
    &:last-child {
      border: 0;
    }
  }
}
</style>
